<html>
<head>
  <title>heat.py</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
<font color="#008000">&quot;&quot;</font><font color="#008000">&quot;
file: heat.py

Based on steady-state.py.

This defines not only the steady state model but also the PyGame code necessary to
visualize it using Surfarray.
&quot;</font><font color="#008000">&quot;&quot;</font>
<strong>import</strong> <font color="#2040a0">sys</font>
<strong>import</strong> <font color="#2040a0">math</font>
<strong>import</strong> <font color="#2040a0">time</font>
<strong>import</strong> <font color="#2040a0">Numeric</font>

<strong>import</strong> <font color="#2040a0">pygame</font>
<strong>from</strong> <font color="#2040a0">pygame</font>.<font color="#2040a0">locals</font> <strong>import</strong> <font color="4444FF">*</font>
<strong>from</strong> <font color="#2040a0">pygame</font> <strong>import</strong> <font color="#2040a0">surfarray</font>

<font color="#2040a0">def</font> <font color="#2040a0">drawfield</font><font color="4444FF">(</font> <font color="#2040a0">screen</font>, <font color="#2040a0">scale_surface</font>, <font color="#2040a0">pixels</font> <font color="4444FF">)</font><font color="4444FF">:</font>
    <font color="#2040a0">surfarray</font>.<font color="#2040a0">blit_array</font><font color="4444FF">(</font> <font color="#2040a0">scale_surface</font>, <font color="#2040a0">pixels</font> <font color="4444FF">)</font>
    <font color="#2040a0">temp</font> <font color="4444FF">=</font> <font color="#2040a0">pygame</font>.<font color="#2040a0">transform</font>.<font color="#2040a0">scale</font><font color="4444FF">(</font><font color="#2040a0">scale_surface</font>, <font color="#2040a0">screen</font>.<font color="#2040a0">get_size</font><font color="4444FF">(</font><font color="4444FF">)</font><font color="4444FF">)</font>
    <font color="#2040a0">screen</font>.<font color="#2040a0">blit</font><font color="4444FF">(</font><font color="#2040a0">temp</font>, <font color="4444FF">(</font><font color="#FF0000">0</font>,<font color="#FF0000">0</font><font color="4444FF">)</font><font color="4444FF">)</font>
    <strong>return</strong>

<font color="#2040a0">def</font> <font color="#2040a0">createPalette</font><font color="4444FF">(</font> <font color="4444FF">)</font><font color="4444FF">:</font>
    <font color="#2040a0">r</font>,<font color="#2040a0">g</font>,<font color="#2040a0">b</font> <font color="4444FF">=</font> <font color="4444FF">-</font><font color="#FF0000">1</font>,<font color="#FF0000">0</font>,<font color="#FF0000">256</font>
    <font color="#2040a0">palette</font> <font color="4444FF">=</font> <font color="4444FF">[</font><font color="4444FF">]</font>
    <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">0</font>,<font color="#FF0000">256</font><font color="4444FF">)</font><font color="4444FF">:</font>
        <font color="#2040a0">r</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#FF0000">1</font>
        <font color="#2040a0">b</font> <font color="4444FF">-</font><font color="4444FF">=</font> <font color="#FF0000">1</font>
        <font color="#2040a0">palette</font>.<font color="#2040a0">append</font><font color="4444FF">(</font> <font color="4444FF">(</font><font color="#2040a0">r</font>,<font color="#2040a0">g</font>,<font color="#2040a0">b</font><font color="4444FF">)</font> <font color="4444FF">)</font>
    <strong>return</strong> <font color="#2040a0">palette</font>    

<font color="#2040a0">def</font> <font color="#2040a0">main</font><font color="4444FF">(</font> <font color="#2040a0">N</font><font color="4444FF">=</font><font color="#FF0000">100</font>, <font color="#2040a0">EPSILON</font> <font color="4444FF">=</font> <font color="#FF0000">0.01</font> <font color="4444FF">)</font><font color="4444FF">:</font>
    <font color="#444444"># Stores Old(previous timestep) Values </font>
    <font color="#2040a0">u</font> <font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">zeros</font><font color="4444FF">(</font> <font color="4444FF">(</font><font color="#2040a0">N</font>,<font color="#2040a0">N</font><font color="4444FF">)</font>,<font color="#2040a0">Numeric</font>.<font color="#2040a0">Float32</font> <font color="4444FF">)</font>
    <font color="#444444"># New(current/next timestep) Values</font>
    <font color="#2040a0">w</font> <font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">zeros</font><font color="4444FF">(</font> <font color="4444FF">(</font><font color="#2040a0">N</font>,<font color="#2040a0">N</font><font color="4444FF">)</font>,<font color="#2040a0">Numeric</font>.<font color="#2040a0">Float32</font> <font color="4444FF">)</font>
    <font color="#2040a0">pixels</font> <font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">zeros</font><font color="4444FF">(</font> <font color="4444FF">(</font><font color="#2040a0">N</font>,<font color="#2040a0">N</font><font color="4444FF">)</font>, <font color="#2040a0">Numeric</font>.<font color="#2040a0">Int32</font> <font color="4444FF">)</font>
    <font color="#444444"># Set boundary values and compute mean boundary value</font>
    <font color="#2040a0">mean</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font>
    <font color="#444444"># This &quot;magic&quot; factor is just a scaling to get the full range of our (255.0/N)</font>
    <font color="#444444"># color palette.</font>
    <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">:</font>
        <font color="#444444"># 3 sides @ 100.0 degrees</font>
        <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">100.0</font>
        <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#FF0000">100</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">255.0</font>/<font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">)</font>
        <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">100.0</font>
        <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#FF0000">100</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">255.0</font>/<font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">)</font>
        <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font>  <font color="4444FF">=</font> <font color="#FF0000">100.0</font>
        <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#FF0000">100</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">255.0</font>/<font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">)</font>
        <font color="#444444"># 1 side @ 0 degrees</font>
    <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">:</font>
        <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font>
        <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font>
        
    <font color="#2040a0">mean</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">sum</font><font color="4444FF">(</font><font color="#2040a0">u</font><font color="4444FF">[</font><font color="4444FF">:</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">)</font>
    <font color="#2040a0">mean</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">sum</font><font color="4444FF">(</font><font color="#2040a0">u</font><font color="4444FF">[</font><font color="4444FF">:</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">)</font>
    <font color="#2040a0">mean</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">sum</font><font color="4444FF">(</font><font color="#2040a0">u</font><font color="4444FF">[</font><font color="#FF0000">0</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="4444FF">:</font><font color="4444FF">]</font><font color="4444FF">)</font>
    <font color="#2040a0">mean</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#2040a0">Numeric</font>.<font color="#2040a0">sum</font><font color="4444FF">(</font><font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="4444FF">:</font><font color="4444FF">]</font><font color="4444FF">)</font>
    <font color="#2040a0">mean</font> /<font color="4444FF">=</font> <font color="4444FF">(</font><font color="#FF0000">4.0</font> <font color="4444FF">*</font> <font color="#2040a0">N</font><font color="4444FF">)</font>

    <font color="#444444"># Initialize interior values:</font>
    <strong>print</strong> <font color="#2040a0">mean</font>
    <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
        <strong>for</strong> <font color="#2040a0">j</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
            <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">mean</font>
            <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#2040a0">mean</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">255.0</font>/<font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">)</font>
    

    <font color="#2040a0">WINSIZE</font> <font color="4444FF">=</font> <font color="#FF0000">640</font>,<font color="#FF0000">480</font>
    <font color="#2040a0">ARRAYSIZE</font> <font color="4444FF">=</font> <font color="#2040a0">N</font>,<font color="#2040a0">N</font>
    
    <font color="#444444"># Initialize the Pygame Engine!</font>
    <font color="#2040a0">pygame</font>.<font color="#2040a0">init</font><font color="4444FF">(</font><font color="4444FF">)</font>
    <font color="#2040a0">screen</font> <font color="4444FF">=</font> <font color="#2040a0">pygame</font>.<font color="#2040a0">display</font>.<font color="#2040a0">set_mode</font><font color="4444FF">(</font><font color="#2040a0">WINSIZE</font>,<font color="#FF0000">0</font>,<font color="#FF0000">8</font><font color="4444FF">)</font>
    <font color="#2040a0">scale_screen</font> <font color="4444FF">=</font> <font color="#2040a0">pygame</font>.<font color="#2040a0">surface</font>.<font color="#2040a0">Surface</font><font color="4444FF">(</font> <font color="#2040a0">ARRAYSIZE</font>,<font color="#FF0000">0</font>,<font color="#FF0000">8</font> <font color="4444FF">)</font>
    <font color="#2040a0">pygame</font>.<font color="#2040a0">display</font>.<font color="#2040a0">set_caption</font><font color="4444FF">(</font><font color="#008000">'Heat'</font><font color="4444FF">)</font>
    <font color="#2040a0">black</font> <font color="4444FF">=</font> <font color="#FF0000">20</font>,<font color="#FF0000">20</font>, <font color="#FF0000">40</font>
    <font color="#2040a0">palette</font> <font color="4444FF">=</font> <font color="#2040a0">createPalette</font><font color="4444FF">(</font><font color="4444FF">)</font>
    <font color="#2040a0">screen</font>.<font color="#2040a0">fill</font><font color="4444FF">(</font><font color="#2040a0">black</font><font color="4444FF">)</font>
    <font color="#2040a0">scale_screen</font>.<font color="#2040a0">fill</font><font color="4444FF">(</font><font color="#2040a0">black</font><font color="4444FF">)</font>
    <font color="#2040a0">screen</font>.<font color="#2040a0">set_palette</font><font color="4444FF">(</font> <font color="#2040a0">palette</font> <font color="4444FF">)</font>
    <font color="#2040a0">scale_screen</font>.<font color="#2040a0">set_palette</font><font color="4444FF">(</font> <font color="#2040a0">palette</font> <font color="4444FF">)</font>
    
    <font color="#444444"># Compute Steady-State solution:</font>
    <font color="#2040a0">done</font> <font color="4444FF">=</font> <font color="#2040a0">False</font> <font color="#444444"># Is true when we reach steady state</font>
    <font color="#2040a0">userquit</font> <font color="4444FF">=</font> <font color="#2040a0">False</font> <font color="#444444"># is true only when the user is done watching</font>
    <font color="#2040a0">iterations</font> <font color="4444FF">=</font> <font color="#FF0000">0</font>
    <strong>while</strong> <strong>not</strong> <font color="#2040a0">userquit</font><font color="4444FF">:</font>
        <font color="#2040a0">iterations</font> <font color="4444FF">+</font><font color="4444FF">=</font> <font color="#FF0000">1</font>
        <font color="#2040a0">delta</font> <font color="4444FF">=</font> <font color="#FF0000">0.0</font>
        <strong>if</strong> <strong>not</strong> <font color="#2040a0">done</font><font color="4444FF">:</font>
            <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
                <strong>for</strong> <font color="#2040a0">j</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
                    <font color="#2040a0">w</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">+</font> <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">+</font> <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">+</font> <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">+</font><font color="#FF0000">1</font><font color="4444FF">]</font>
                    <font color="#2040a0">w</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> /<font color="4444FF">=</font> <font color="#FF0000">4.0</font>
                    <font color="#2040a0">d</font> <font color="4444FF">=</font> <font color="#2040a0">math</font>.<font color="#2040a0">fabs</font><font color="4444FF">(</font> <font color="#2040a0">w</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">-</font> <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">)</font> 
                    <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">d</font> <font color="4444FF">&gt;</font> <font color="#2040a0">delta</font> <font color="4444FF">)</font><font color="4444FF">:</font>
                        <font color="#2040a0">delta</font> <font color="4444FF">=</font> <font color="#2040a0">d</font>
            <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">delta</font> <font color="4444FF">&lt;</font><font color="4444FF">=</font> <font color="#2040a0">EPSILON</font> <font color="4444FF">)</font><font color="4444FF">:</font>
                <font color="#2040a0">done</font> <font color="4444FF">=</font> <font color="#2040a0">True</font>
            <font color="#444444"># Copy new interior state to old:</font>
            <strong>for</strong> <font color="#2040a0">i</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
                <strong>for</strong> <font color="#2040a0">j</font> <strong>in</strong> <font color="#2040a0">xrange</font><font color="4444FF">(</font><font color="#FF0000">1</font>,<font color="#2040a0">N</font><font color="4444FF">-</font><font color="#FF0000">1</font><font color="4444FF">)</font><font color="4444FF">:</font>
                    <font color="#2040a0">u</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">w</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font>
                    <font color="#2040a0">pixels</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font><font color="#2040a0">w</font><font color="4444FF">[</font><font color="#2040a0">i</font><font color="4444FF">]</font><font color="4444FF">[</font><font color="#2040a0">j</font><font color="4444FF">]</font> <font color="4444FF">*</font> <font color="4444FF">(</font><font color="#FF0000">255.0</font>/<font color="#2040a0">N</font><font color="4444FF">)</font><font color="4444FF">)</font> 
        <font color="#444444"># Draw</font>
        <font color="#2040a0">drawfield</font><font color="4444FF">(</font> <font color="#2040a0">screen</font>, <font color="#2040a0">scale_screen</font>, <font color="#2040a0">pixels</font> <font color="4444FF">)</font>
        <font color="#2040a0">pygame</font>.<font color="#2040a0">display</font>.<font color="#2040a0">update</font><font color="4444FF">(</font><font color="4444FF">)</font>
        <font color="#444444"># Handle Events</font>
        <font color="#2040a0">events</font> <font color="4444FF">=</font> <font color="#2040a0">pygame</font>.<font color="#2040a0">event</font>.<font color="#2040a0">get</font><font color="4444FF">(</font> <font color="4444FF">)</font>
        <strong>for</strong> <font color="#2040a0">e</font> <strong>in</strong> <font color="#2040a0">events</font><font color="4444FF">:</font>
            <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">e</font>.<font color="#2040a0">type</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">QUIT</font> <font color="4444FF">)</font><font color="4444FF">:</font>
                <font color="#2040a0">userquit</font> <font color="4444FF">=</font> <font color="#2040a0">True</font>
                <strong>break</strong>
            <strong>elif</strong> <font color="4444FF">(</font><font color="#2040a0">e</font>.<font color="#2040a0">type</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">KEYDOWN</font><font color="4444FF">)</font><font color="4444FF">:</font>
                <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">e</font>.<font color="#2040a0">key</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">K_ESCAPE</font> <font color="4444FF">)</font><font color="4444FF">:</font>
                    <font color="#2040a0">userquit</font> <font color="4444FF">=</font> <font color="#2040a0">True</font>
                    <strong>break</strong>
                <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">e</font>.<font color="#2040a0">key</font> <font color="4444FF">=</font><font color="4444FF">=</font> <font color="#2040a0">K_f</font> <font color="4444FF">)</font><font color="4444FF">:</font>
                    <font color="#2040a0">pygame</font>.<font color="#2040a0">display</font>.<font color="#2040a0">toggle_fullscreen</font><font color="4444FF">(</font><font color="4444FF">)</font>

    <font color="#444444"># Print Solution:</font>
    <strong>print</strong> <font color="#2040a0">u</font>
    <strong>return</strong> <font color="#2040a0">iterations</font>
                    
<strong>if</strong> <font color="#2040a0">__name__</font><font color="4444FF">=</font><font color="4444FF">=</font><font color="#008000">&quot;__main__&quot;</font><font color="4444FF">:</font>
    <strong>print</strong> <font color="#008000">&quot;Starting Steady State Example:&quot;</font>
    <strong>if</strong><font color="4444FF">(</font> <font color="#2040a0">len</font><font color="4444FF">(</font><font color="#2040a0">sys</font>.<font color="#2040a0">argv</font><font color="4444FF">)</font> <font color="4444FF">&gt;</font><font color="4444FF">=</font> <font color="#FF0000">2</font> <font color="4444FF">)</font><font color="4444FF">:</font>
        <font color="#2040a0">N</font> <font color="4444FF">=</font> <font color="#2040a0">int</font><font color="4444FF">(</font> <font color="#2040a0">sys</font>.<font color="#2040a0">argv</font><font color="4444FF">[</font><font color="#FF0000">1</font><font color="4444FF">]</font> <font color="4444FF">)</font>
    <strong>else</strong><font color="4444FF">:</font>
        <font color="#2040a0">N</font> <font color="4444FF">=</font> <font color="#FF0000">100</font>
    <font color="#2040a0">start</font> <font color="4444FF">=</font> <font color="#2040a0">time</font>.<font color="#2040a0">time</font><font color="4444FF">(</font><font color="4444FF">)</font>
    <font color="#2040a0">iterations</font> <font color="4444FF">=</font> <font color="#2040a0">main</font><font color="4444FF">(</font><font color="#2040a0">N</font><font color="4444FF">)</font>
    <font color="#2040a0">end</font> <font color="4444FF">=</font> <font color="#2040a0">time</font>.<font color="#2040a0">time</font><font color="4444FF">(</font><font color="4444FF">)</font>
    <strong>print</strong> <font color="#008000">&quot;Finished Steady State Example in&quot;</font>,<font color="#2040a0">end</font> <font color="4444FF">-</font> <font color="#2040a0">start</font>,<font color="#008000">&quot;and&quot;</font>,<font color="#2040a0">iterations</font>,<font color="#008000">&quot;iterations.&quot;</font>

</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
